Skip to content

Tests: Add missing @covers tags and refactor invalid block name tests to use a data provider#11524

Open
sagarsdeshmukh wants to merge 1 commit intoWordPress:trunkfrom
sagarsdeshmukh:add-covers-and-data-providers
Open

Tests: Add missing @covers tags and refactor invalid block name tests to use a data provider#11524
sagarsdeshmukh wants to merge 1 commit intoWordPress:trunkfrom
sagarsdeshmukh:add-covers-and-data-providers

Conversation

@sagarsdeshmukh
Copy link
Copy Markdown

@sagarsdeshmukh sagarsdeshmukh commented Apr 9, 2026

What

This PR makes two types of test improvements across three test files.


1. Add missing @covers annotations

Adds @covers tags to test classes that were missing them, as part of the ongoing effort in #64225:

File Annotation added
tests/phpunit/tests/rewrite/addRewriteRule.php @covers ::add_rewrite_rule
tests/phpunit/tests/rewrite/addRewriteEndpoint.php @covers ::add_rewrite_endpoint
tests/phpunit/tests/blocks/wpBlockTypeRegistry.php @covers WP_Block_Type_Registry

Both add_rewrite_rule() and add_rewrite_endpoint() are defined in src/wp-includes/rewrite.php.

Without @covers, PHPUnit cannot correctly attribute code coverage to the functions under test, which leads to inaccurate coverage reports on Codecov.


2. Refactor repeated invalid block name tests to use a data provider

In Tests_Blocks_wpBlockTypeRegistry, four separate test methods were structurally identical — each registered one invalid block name and asserted false:

  • test_invalid_non_string_names()
  • test_invalid_names_without_namespace()
  • test_invalid_characters()
  • test_uppercase_characters()

These have been consolidated into a single test_invalid_block_names() method backed by a data_invalid_block_names() data provider with named cases, following the same pattern used in recently updated tests across the suite.

Before: 4 methods × ~9 lines each = ~36 lines

After: 1 method + 1 data provider = ~21 lines

Named data sets also make PHPUnit failure output more readable — instead of test_invalid_characters you see test_invalid_block_names with data set "invalid characters", which is clearer at a glance.


Testing

Ran all three affected test classes locally:                                                                              

npm run test:php -- --filter "Tests_Rewrite_AddRewriteRule|Tests_Rewrite_AddRewriteEndpoint|Tests_Blocks_wpBlockTypeRegistry"                                                       
                                                                                                                             
OK (20 tests, 42 assertions)

All passing. The data provider runs each case as its own PHPUnit test, so the assertion count is unchanged.


Trac

See https://core.trac.wordpress.org/ticket/64225

This is my first contribution to WordPress core. I've enabled "Allow and access to secrets by maintainers". Happy to adjust anything based on review feedback.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 9, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props sagardeshmukh.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant